#include "games/randomgame.h"

RandomGame::RandomGame(QWidget *parent, int difflvl) :
    BaseGame(parent, difflvl)
{
    no_btns = difficulty_level + 1;

    check_map = new QCheckBox*[no_btns];
    button_map = new QPushButton*[no_btns];
    bool_map = new bool[no_btns];


    for(int i = 0; i < no_btns; i++) {
        QCheckBox * c = new QCheckBox(this);
        QPushButton * p = new QPushButton(this);
        c->setCheckable(false);
        check_map[i] = c;
        button_map[i] = p;
        bool_map[i] = false;
        connect(p,SIGNAL(clicked()),this,SLOT(onButtonClicked()));
        lay->addWidget(c,0,i);
        lay->addWidget(p,1,i);
    }

    lay->setAlignment(Qt::AlignHCenter);

}

bool RandomGame::isSolved()
{
    for(int i = 0; i < no_btns; i++) if(bool_map[i] == false) return false;
    return true;
}

void RandomGame::onButtonClicked()
{
    int rand = qrand() % no_btns;
    if(bool_map[rand] == false) check_map[rand]->setChecked(true);
    else check_map[rand]->setChecked(false);
    bool_map[rand] = !bool_map[rand];
}
